<template>
    <div>
        <el-dialog top="5%" :title="title" size="large" v-model="editFormVisible" :close-on-click-modal="false">
           <Approve @onApproveSuc="onApproveSuc" :showcontent="showcontent" ref="approve" v-if="ApproveID"></Approve>
            <el-tag v-if="ApproveID"  style="font-size: larger; margin: 10px 0px 10px 10px;">员工信息</el-tag>
            <div style="border: 1px solid #bbb; padding: 20px;">
            <el-form  ref="form" :model="form" :inline="true" :rules="rules" label-width="70px">
                <el-form-item label="姓名">
                    <el-input v-model="form.FName" style="width:220px;"></el-input>
                </el-form-item>
                <el-form-item label="性别" placeholder="请选择"  prop="FSex">
                    <el-select v-model="form.FSex" placeholder="请选择" style="width: 100%">
                        <el-option label="男" value="男"></el-option>
                        <el-option label="女" value="女"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="身份证号">
                    <el-input v-model="form.FIdCardNo" style="width:220px;"></el-input>
                </el-form-item>
                <el-form-item label="手机号">
                    <el-input v-model="form.FPhone" style="width:220px;"></el-input>
                </el-form-item>
                <el-form-item label="部门" placeholder="请选择"  prop="FDeptID">
                <sy-select v-model="form.FDeptID"  valueKey="FID" style="width:220px"
                           optionData="server/system/Dept.ashx?cmd=GetOptions">
                </sy-select>
                </el-form-item>
                <el-form-item label="入职时间">
                    <el-date-picker type="date"  v-model="form.FEntryDate"  style="width:220px"></el-date-picker>
                </el-form-item>
                <el-form-item label="月薪(元)">
                    <el-input type="number" v-model="form.FSalary" style="width:220px;"></el-input>
                </el-form-item>
                <el-form-item label="职务">
                    <el-input v-model="form.FPost" style="width:220px;"></el-input>
                </el-form-item>
                <el-form-item label="备注">
                    <el-input type="textarea" v-model="form.FNote" style="width:850px;"></el-input>
                </el-form-item>
            </el-form>
            </div>
                <div slot="footer" class="dialog-footer">
                <el-button @click.native="editFormVisible = false">取 消</el-button>
                <el-button type="primary" v-if="showSave" @click="save" :loading="loading">保存</el-button>
            </div>
      </el-dialog>
    </div>
</template>

<script>
    import util from '../../common/util'
    import mixin from '../../common/mixin'
    import Approve from './Approve.vue'
    import Vue from 'vue'
    export default {
        components:{
            Approve:Approve
        },
        data() {
            return {
                form: {},
                showSave:true,
                rules: {
                   // FName: [{type: "date",name:"FCreateDate",text:"跟进时间", value: null}]
                },
                loading:false,
                editFormVisible:false,
                title:'',
                listLoading:false,
                ApproveID:null,
                showcontent:true,
                fixWhere:'',
            }
        },
        computed: {

        },
        methods: {
            switchLoading(flag){
                this.loading = flag;
            },
            _openEdit(record) {
                this.editFormVisible = true
                this.form = Object.assign({},record)
                this.title = '编辑'
            },
            _openAdd(record) {
                this.editFormVisible = true
                this.form = {FID:0,FStatus:0,FEntryDate:null,FSex:null,FCreateUserID:global.user.FID,FCreateDate:new Date()}
                this.title = '新增'
            },
            _openApprove(record,ApproveID) {
                this.editFormVisible = true;
                this.ApproveID = ApproveID
                this.form = Object.assign({},record);
                if(record.FApproveStatus!=0&&record.FApproveStatus!=-1){
                if((record.FToApprover!=global.user.FID)||record.FApproveStatus==3)
                {
                    this.showSave=false
                    this.showcontent=false
                    this.title='查看'
                }
                else {
                    this.title='审核'
                }
                }
                if(record.FApproveStatus==0||record.FApproveStatus==-1) {
                    this.title='提交审核'
                }

                this.$nextTick(()=>{
                    this.$refs.approve._init(record,ApproveID);
                })

            },
            save:function () {
                util.post("server/system/User.ashx?cmd=SaveUser",this.form,this.switchLoading,result=> {
                    util.msgSuc("保存成功")
                    if(!this.ApproveID) {
                        this.editFormVisible = false
                        this.$emit("onSaveSuc", this.form)
                    }
                })
            },
            onApproveSuc()
            {
                global.bus.$emit('RefreshMsgCount')
                this.editFormVisible = false
                this.$emit("onSaveSuc", this.form)
            }
        },
        mounted() {

        }
    }
</script>
